package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.BankInterfaceBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.BankInterfaceMapper;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.bson.types.ObjectId;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class BankInterfaceAdd implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<String> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", String.class);
		try {
			BankInterfaceMapper mapper = factory.getMapper(BankInterfaceMapper.class);

			BankInterfaceBean bean = JsonUtils.objectToPojo(req.getData(), BankInterfaceBean.class);
			bean.setBankInterfaceId(new ObjectId().toHexString());
			//bean.setCreateName(userInfo.getUserInfo().getName()); //TODO redis报错
			bean.setCreateTime(CommonUtils.getCurrentTime());			

			//bean.setStatus(1);
			mapper.insertBankInterface(bean);
			info.setData(bean.getBankInterfaceId());
			return info;
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
	}

}
